package origin

import (
	"golang.org/x/net/websocket"
	"net/http"
	"strings"
	"tradove/blockchain/src/github.com/sirupsen/logrus"
)

type WsServer struct {

}

func (wsServer *WsServer) WsServe(){
	var msg string
	logrus.Info("ws serve triggered.")

	http.Handle("/ws_msg", websocket.Handler(func (ws *websocket.Conn){
		logrus.Info("get client msg...")
		defer ws.Close()
		err := websocket.Message.Receive(ws, &msg)
		if err != nil {
			logrus.Error("receive message error: ", err.Error())
		}
		logrus.Info("receive client message: ", msg)

		err = websocket.Message.Send(ws, strings.ToUpper(msg))
		if err != nil {
			logrus.Error("send upper message error: ", err.Error())
		}
	}))
}